home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / poly.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  3KB  |  81 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                              N O T I C E                             *
  4.  *                                                                      *
  5.  *                      Copyright Abandoned, 1987, Fred Fish            *
  6.  *                                                                      *
  7.  *      This previously copyrighted work has been placed into the       *
  8.  *      public domain by the author (Fred Fish) and may be freely used  *
  9.  *      for any purpose, private or commercial.  I would appreciate     *
  10.  *      it, as a courtesy, if this notice is left in all copies and     *
  11.  *      derivative works.  Thank you, and enjoy...                      *
  12.  *                                                                      *
  13.  *      The author makes no warranty of any kind with respect to this   *
  14.  *      product and explicitly disclaims any implied warranties of      *
  15.  *      merchantability or fitness for any particular purpose.          *
  16.  *                                                                      *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *      poly   double precision polynomial evaluation
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *      poly
  28.  *      machine independent routines
  29.  *      math libraries
  30.  *
  31.  *  DESCRIPTION
  32.  *
  33.  *      Evaluates a polynomial and returns double precision
  34.  *      result.  Is passed a the order of the polynomial,
  35.  *      a pointer to an array of double precision polynomial
  36.  *      coefficients (in ascending order), and the independent
  37.  *      variable.
  38.  *
  39.  *  USAGE
  40.  *
  41.  *      double poly (order, coeffs, x)
  42.  *      int order;
  43.  *      double *coeffs;
  44.  *      double x;
  45.  *
  46.  *  PROGRAMMER
  47.  *
  48.  *      Fred Fish
  49.  *
  50.  *  INTERNALS
  51.  *
  52.  *      Evalates the polynomial using recursion and the form:
  53.  *
  54.  *              P(x) = P0 + x(P1 + x(P2 +...x(Pn)))
  55.  *
  56.  */
  57.  
  58. #include <stdio.h>
  59. #include "pml.h"
  60.  
  61. double poly (order, coeffs, x)
  62. register int order;
  63. double *coeffs;
  64. double x;
  65. {
  66.     double curr_coeff;
  67.     double rtn_value;
  68.  
  69.     DBUG_ENTER ("poly");
  70.     DBUG_5 ("polyin", "args %d %#x %le", order, coeffs, x);
  71.     if (order <= 0) {
  72.         rtn_value = *coeffs;
  73.     } else {
  74.         curr_coeff = *coeffs;   /* Bug in Unisoft's compiler.  Does not */
  75.         coeffs++;               /* generate good code for *coeffs++ */
  76.         rtn_value = curr_coeff + x * poly (--order, coeffs, x);
  77.     }
  78.     DBUG_3 ("polyout", "result %le", rtn_value);
  79.     DBUG_RETURN (rtn_value);
  80. }
  81.